package cn.com.crc.ems.rest.controller;

import cn.com.crc.ems.rest.common.Result;
import cn.com.crc.ems.rest.dto.FormStructure;
import cn.com.crc.ems.rest.dto.QueryDto;
import cn.com.crc.ems.rest.service.LuceneService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/lucene")
@Api(value = "lucene", description = "lucene")
public class LuceneController {


    @Autowired
    private LuceneService luceneService;


    @ApiOperation("导入数据至lucene")
    @PostMapping("/importDataToLucene")
    public Result importDataToLucene(@RequestBody List<FormStructure> formStructureList) {
        luceneService.importDataToLucene(formStructureList);
        return Result.makeSuccess();
    }


    @ApiOperation("查询数据")
    @PostMapping("/searchData")
    public List<FormStructure> searchData(@RequestBody QueryDto query) {
        List<FormStructure> formStructureList = luceneService.searchData(query);
        return formStructureList;
    }

    @ApiOperation("删除数据")
    @PostMapping("/delData")
    public Result delData(String formId) {
        luceneService.delData(formId);
        return Result.makeSuccess();
    }

    @ApiOperation("更新数据")
    @PostMapping("/updateData")
    public Result updateData(@RequestBody FormStructure formStructure) {
        luceneService.updateData(formStructure);
        return Result.makeSuccess();
    }
}
